package pers.baiban.sqltoword.handler.impl;

import pers.baiban.sqltoword.handler.AbstractTableProcessor;
import pers.baiban.sqltoword.handler.TableProcessor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 表格上边框处理器
 *
 * @author 强子初
 * @since 2023/11/29
 */
@Component
@Order(5)
public class TableBorderTopProcessor extends AbstractTableProcessor implements TableProcessor {

    @Override
    public void doHandler() {
        if (needUpdate(param.getTableBorderTop())) {
            getTop().setVal(param.getTableBorderTop());
        }

        if (needUpdate(param.getTableBorderTopWidth())) {
            getTop().setSz(param.getTableBorderTopWidth());
        }
    }

    /**
     * 获取表格上边框
     */
    private CTBorder getTop() {
        return borders.isSetTop() ? borders.getTop() : borders.addNewTop();
    }
}